package com.ruiyun.app.lib.logcat;

import android.app.Application;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.widget.Toast;

import com.ruiyun.app.lib.crash.CrashHandler;
import com.ruiyun.app.lib.utils.MetaDataUtil;
import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;



/**
 * desc   : Logcat 初始化
 */
public final class InitProvider extends ContentProvider {

    @Override
    public boolean onCreate() {
        Context context = getContext();
        if (context != null) {
            LogcatConfig.init(context.getApplicationContext());
            if (context instanceof Application) {
                boolean upload = MetaDataUtil.Companion.getBoolean("UPLOADLOGCAT",context);
                if (upload) {
                    UMConfigure.init(context, MetaDataUtil.Companion.getString("LOGCATKEY",context), "umeng", UMConfigure.DEVICE_TYPE_PHONE, "");
                    MobclickAgent.setCatchUncaughtExceptions(false);
                } else {
                    FloatingLifecycle.with((Application) context);
                }
                // 本地异常捕捉
                CrashHandler.Companion.getInstance().init((Application) context, upload);
            } else {
                Toast.makeText(context, "参数错误，无法启动 Logcat", Toast.LENGTH_LONG).show();
            }
        }
        return true;
    }

    @Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
        return null;
    }

    @Override
    public String getType(Uri uri) {
        return null;
    }

    @Override
    public Uri insert(Uri uri, ContentValues values) {
        return null;
    }

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        return 0;
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        return 0;
    }
}